﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
using ExtBusiness.User;
using ExtBusiness.Interface;

public partial class WebPubManager_UserList : System.Web.UI.Page
{
    private UserManager cUser = new UserManager();

    protected void Page_Load(object sender, EventArgs e)
    {
        string strId = Request.Params["id"];
        InterfaceOperation infaceOperation = new InterfaceOperation();
        string strXml = string.Empty;

        try
        {
            if (Request.Params["action"] == "delete")
            {
                //更新用户信息 
                strXml = infaceOperation.GetUserInfoXml(strId, "delete");

                UserManager.DeleteUser(strId);//删除用户
            }
            if (Request.Params["action"] == "reset")
            {
                //先更新密码
                UserManager.UpdatePassword(strId);

                //更新用户信息 
                strXml = infaceOperation.GetUserInfoXml(strId, "update");

                //if (!string.IsNullOrEmpty(strXml))
                //{

                //    string strCheckCode = Common.Encode.Md5(DateTime.Now.ToShortDateString());
                //}
            }
        }
        catch (Exception ex)
        {
            if (!string.IsNullOrEmpty(strXml))
            {
                infaceOperation.UpdateExceptionAndXml(strXml, ex.Message, 10);
            }
        }

        if (!IsPostBack)
        {
            GridviewDatabind();
        }
    }

    #region 数据绑定
    /// <summary>
    /// Gridviews the databind.
    /// </summary>
    private void GridviewDatabind()
    {
        DataTable dt = cUser.GetUser();
        gridviewCar.DataSource = dt;
        gridviewCar.RecordCount = dt.Rows.Count;
        gridviewCar.DataBind();
    }
    #endregion 

    /// <summary>
    /// datagrid数据加载
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void recvgrid_OnLoadData(object sender, EventArgs e)
    {
        this.GridviewDatabind();
    }

    #region 行创建
    /// <summary>
    /// Handles the RowCreated event of the gridviewCar control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.Web.UI.WebControls.GridViewRowEventArgs"/> instance containing the event data.</param>
    protected void gridviewCar_RowCreated(object sender, GridViewRowEventArgs e)
    {
        switch (e.Row.RowType)
        {
            case DataControlRowType.DataRow:

                DataRowView drv = e.Row.DataItem as DataRowView;
                if (drv == null)
                {
                    break;
                }
                HyperLink hyedit = e.Row.FindControl("hyedit") as HyperLink;
                if (hyedit != null)
                {
                    hyedit.NavigateUrl = "UserEdit.aspx?id=" + drv["id"];
                }

                HyperLink hydel = e.Row.FindControl("hydel") as HyperLink;
                if (hydel != null)
                {
                    hydel.Attributes.Add("OnClick", "return confirm('确定要删除该用户?')");
                    hydel.NavigateUrl = "UserList.aspx?action=delete&id=" + drv["id"];
                }
                break;
        }
    }
    #endregion
}
